package br.com.amadeus.android.activities.course;

import java.util.List;

import br.com.amadeus.android.activities.home.R;
import br.com.amadeus.android.adapters.MyCoursesListAdapter;
import br.com.amadeus.android.business.FacadeAmadeusDroid;
import br.com.amadeus.android.entities.Course;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class CourseOffActivity extends Activity{
	
	public static final int ACTIVE = 0;
	private ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.inactive_courses);
		
		List<Course> listInactiveCourses = FacadeAmadeusDroid.getInstance(this).getListInactiveCourses();
		
		MyCoursesListAdapter adapter = new MyCoursesListAdapter(this, listInactiveCourses);
		
		this.listView = (ListView) findViewById(R.id.lvInactiveCourses);
		this.listView.setAdapter(adapter);
		
		this.listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View v, int posicao, long id) {
				
				Course course = (Course) listView.getAdapter().getItem(posicao);
				
				Intent it = new Intent("HOME_COURSE");
				Bundle basket = new Bundle();
				basket.putInt("course_id", course.getId());
				it.putExtras(basket);
				startActivity(it);
				
			}
		});
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		MenuItem item = menu.add(0, ACTIVE, 0, "Cursos Ativos");
		
		return true;
	}
	
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case ACTIVE:
			startActivity(new Intent("COURSEON"));
			return true;
		}
		return false;
	}

}
